<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        html {
            width: 960;
            height: 800px;
        }

        body {
            width: 100%;
            height: 100%;
            background: bisque;
        }

        p {
            width: 100px;
            height: 100px;
            background: blue;
            position: absolute;
            border-radius: 50%;
        }

        h1 {
            position: absolute;
        }

        h2 {
            position: absolute;
            left: 500px;
        }

        button {
            position: absolute;
        }

        .div1 {
            width: 300px;
            height: 50px;
            position: absolute;
            left: 800px;
            border: solid 2px pink;
        }

        .div2 {
            width: 300px;
            height: 50px;
            background: red;
        }
    </style>
</head>

<body>
    <h1>点击开始，进入极速反应模式</h1>
    <h2></h2>
    <button>开始</button>
    <div class="div1">
        <div class="div2"></div>
        <h3>血量</h3>
    </div>
</body>

</html>
<script>
    document.querySelector('button').onclick = function () {
        var gg = 300
        var div2 = document.querySelector('.div2')
        var tt = 0
        setInterval(function () {
            gg -= 10
            if (gg >= 300) {
                gg = 300
            } else if (gg == 0) {
                alert('你死了，点击刷新页面重新开始游戏；'+'你的分数是'+kk+'分')
            }
            tt++
            document.querySelector('h2').innerText = '你已经坚持了' + tt + '秒'
            div2.style.width = gg + 'px'
        }, 1000)
        var hh = document.querySelector('h1')
        var kk = 0
        var pp = 300
        setInterval(function () {
            var bazi = document.createElement('p')
            document.querySelector('body').appendChild(bazi)
            var max = document.documentElement.clientHeight - bazi.offsetHeight - 50
            var max1 = document.documentElement.clientWidth - bazi.offsetWidth - 50
            var min = 0
            var s = Math.floor(Math.random() * (max - min + 1) + min)
            var b = Math.floor(Math.random() * (max1 - min + 1) + min)
            bazi.style.top = s - 50 + 'px'
            bazi.style.left = b - 50 + 'px'
            bazi.onmousemove = function () {
                this.style.display = 'none'
                kk += 1
                gg += 10
            }
            if (pp >= 250) {
                hh.innerHTML = '简易模式----' + '分数：' + kk
            } else if (pp <= 150) {
                hh.innerHTML = '中等模式----' + '分数：' + kk
            } else if (pp <= 100) {
                hh.innerHTML = '困难模式----' + '分数：' + kk
            } else if (pp <= 30) {
                hh.innerHTML = '地狱模式----' + '分数：' + kk
            } else if (pp <= 0) {
                hh.innerHTML = '丧心病狂----' + '分数：' + kk
            }
            pp--
        }, pp)



        // document.onkeydown = function (e) {
        //     var e = e || window.event
        //     var num = e.keyCode || e.which
        //     if (num === 13 && e.ctrlKey) {
        //         console.log(13);
        //     }
    }
</script>